# -*- coding: utf-8 -*-

from ir.ir_ds import ITypeStruct

from hbcxx.cxx_format import *
from hbcxx.simcxx_types import simcxx_get_type


def simcxx_create_struct(ir_pack: ITypeStruct):
    pack_code = ['typedef struct {}'.format(ir_pack.name),
                 '{']
    for member, member_type in zip(ir_pack.member, ir_pack.member_type):
        pack_code.append(CXX_INDENT + '{} {};'.format(
            simcxx_get_type(member_type), member))
    pack_code.append('} '+'{};'.format(ir_pack.name))
    return '\n'.join(pack_code)


def simcxx_convert_pack(ir_packs: list):
    # Prepare the definitions.
    cxx_pack = []
    # Convert pack definition.
    for ir_pack in ir_packs:
        cxx_pack.append(simcxx_create_struct(ir_pack))
    return cxx_pack
